package tehMod;

import net.minecraft.src.*;
import org.lwjgl.opengl.GL11;

public class RenderTehVillager extends RenderLiving
{
    protected ModelBiped field_40295_c;
    protected ModelBiped modelBiped;

    public RenderTehVillager()
    {
        super(new ModelBiped(0.0F), 0.5F);
        field_40295_c = (ModelBiped)mainModel;
        modelBiped = field_40295_c;
    }

    protected int func_40293_a(EntityTehVillager entityvillager, int i, float f)
    {
        return -1;
    }

    public void renderTehVillager(EntityTehVillager EntityTehVillager, double d, double d1, double d2,
            float f, float f1)
    {
        super.doRenderLiving(EntityTehVillager, d, d1, d2, f, f1);
    }

    protected void func_40290_a(EntityTehVillager EntityTehVillager, double d, double d1, double d2)
    {
    }

    protected void func_40291_a(EntityTehVillager EntityTehVillager, float f)
    {
        super.renderEquippedItems(EntityTehVillager, f);
        ItemStack itemstack1 = EntityTehVillager.inventory.getCurrentItem();
        if (itemstack1 != null)
        {
            GL11.glPushMatrix();
            modelBiped.bipedRightArm.postRender(0.0625F);
            GL11.glTranslatef(-0.0625F, 0.4375F, 0.0625F);
            EnumAction enumaction = null;
            if (EntityTehVillager.getItemInUseCount() > 0)
            {
                enumaction = itemstack1.getItemUseAction();
            }
            if (itemstack1.itemID < 256 && RenderBlocks.renderItemIn3d(Block.blocksList[itemstack1.itemID].getRenderType()))
            {
                float f4 = 0.5F;
                GL11.glTranslatef(0.0F, 0.1875F, -0.3125F);
                f4 *= 0.75F;
                GL11.glRotatef(20F, 1.0F, 0.0F, 0.0F);
                GL11.glRotatef(45F, 0.0F, 1.0F, 0.0F);
                GL11.glScalef(f4, -f4, f4);
            }
            else if (itemstack1.itemID == Item.bow.shiftedIndex)
            {
                float f5 = 0.625F;
                GL11.glTranslatef(0.0F, 0.125F, 0.3125F);
                GL11.glRotatef(-20F, 0.0F, 1.0F, 0.0F);
                GL11.glScalef(f5, -f5, f5);
                GL11.glRotatef(-100F, 1.0F, 0.0F, 0.0F);
                GL11.glRotatef(45F, 0.0F, 1.0F, 0.0F);
            }
            else if (Item.itemsList[itemstack1.itemID].isFull3D())
            {
                float f6 = 0.625F;
                if (Item.itemsList[itemstack1.itemID].shouldRotateAroundWhenRendering())
                {
                    GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
                    GL11.glTranslatef(0.0F, -0.125F, 0.0F);
                }
                if (enumaction == EnumAction.block)
                {
                    GL11.glTranslatef(0.05F, 0.0F, -0.1F);
                    GL11.glRotatef(-50F, 0.0F, 1.0F, 0.0F);
                    GL11.glRotatef(-10F, 1.0F, 0.0F, 0.0F);
                    GL11.glRotatef(-60F, 0.0F, 0.0F, 1.0F);
                }
                GL11.glTranslatef(0.0F, 0.1875F, 0.0F);
                GL11.glScalef(f6, -f6, f6);
                GL11.glRotatef(-100F, 1.0F, 0.0F, 0.0F);
                GL11.glRotatef(45F, 0.0F, 1.0F, 0.0F);
            }
            else
            {
                float f7 = 0.375F;
                GL11.glTranslatef(0.25F, 0.1875F, -0.1875F);
                GL11.glScalef(f7, f7, f7);
                GL11.glRotatef(60F, 0.0F, 0.0F, 1.0F);
                GL11.glRotatef(-90F, 1.0F, 0.0F, 0.0F);
                GL11.glRotatef(20F, 0.0F, 0.0F, 1.0F);
            }
            if (itemstack1.getItem().func_46058_c())
            {
                for (int j = 0; j <= 1; j++)
                {
                    int k = itemstack1.getItem().getColorFromDamage(itemstack1.getItemDamage(), j);
                    float f9 = (float)(k >> 16 & 0xff) / 255F;
                    float f10 = (float)(k >> 8 & 0xff) / 255F;
                    float f12 = (float)(k & 0xff) / 255F;
                    GL11.glColor4f(f9, f10, f12, 1.0F);
                    renderManager.itemRenderer.renderItem(EntityTehVillager, itemstack1, j);
                }
            }
            else
            {
                renderManager.itemRenderer.renderItem(EntityTehVillager, itemstack1, 0);
            }
            GL11.glPopMatrix();
        }
    }

    protected void func_40292_b(EntityTehVillager EntityTehVillager, float f)
    {
        float f1 = 0.9375F;
        GL11.glScalef(f1, f1, f1);
    }

    protected void passSpecialRender(EntityLiving entityliving, double d, double d1, double d2)
    {
        func_40290_a((EntityTehVillager)entityliving, d, d1, d2);
    }

    protected void preRenderCallback(EntityLiving entityliving, float f)
    {
        func_40292_b((EntityTehVillager)entityliving, f);
    }

    protected int shouldRenderPass(EntityLiving entityliving, int i, float f)
    {
        return func_40293_a((EntityTehVillager)entityliving, i, f);
    }

    protected void renderEquippedItems(EntityLiving entityliving, float f)
    {
        func_40291_a((EntityTehVillager)entityliving, f);
    }

    public void doRenderLiving(EntityLiving entityliving, double d, double d1, double d2,
            float f, float f1)
    {
        renderTehVillager((EntityTehVillager)entityliving, d, d1, d2, f, f1);
    }

    public void doRender(Entity entity, double d, double d1, double d2,
            float f, float f1)
    {
        renderTehVillager((EntityTehVillager)entity, d, d1, d2, f, f1);
    }
}
